layui.config({
	base : "js/"
}).use(['form','layer','jquery','layedit','laydate','upload'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		layedit = layui.layedit,
		laydate = layui.laydate,
		$ = layui.jquery;


        layui.upload({
			url: '/file/single',
			success: function(res){
				console.log(res); //上传成功返回值，必须为json格式
				if(res.code==200){
					$('.layui-circle').attr('src',res.message);
					$('.logo').val(res.message);
				}else{

				}
			}
   		 });

	//创建一个编辑器
 	form.on("submit(addNews)",function(data){

        var addData = $('#form').serialize();
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});

        $.ajax({
            type: 'POST',
            url: data.form.action,
            data: addData,
            dataType: 'json',
			success:function(resp){
				console.info(resp);
				if(resp.code == 200){
                    setTimeout(function(){
                        top.layer.close(index);
                        top.layer.msg("渠道添加成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    },1000);
				}else{
                    top.layer.msg(resp.message);
				}
			}
        });


 		return false;
 	})







})
